﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using blackhouse.WebNemo.Business.Groups;
using System.Web.UI;
using blackhouse.JavaScript.JQuery;
using System.Globalization;
using System.Web.UI.WebControls;

namespace blackhouse.WebNemo.Web.Controls {
    public abstract class EditRecordValue : Control {

        #region Fields

        protected GroupColumn column;
        protected GroupRecord record;

        #endregion

        #region Properties

        public abstract bool DisplayInline { get; }

        #endregion

        #region Methods

        public virtual string AppendToHolderCssClass() {
            return "record" + this.column.ColumnType.ToString().ToLower();
        }

        public virtual void SetControl(GroupColumn column, GroupRecord record) {
            this.column = column;
            this.record = record;

            if (this.column != null && this.record != null) {
                this.Visible = true;
                this.PopulateControl();
                JQueryLibraries jql = new JQueryLibraries();
                jql.IncludeJQueryMain(true);
                jql.IncludeJQueryKeyFilter();
                jql.IncludeJQueryUI();
                jql.IncludeJQueryUICulture(CultureInfo.CurrentCulture);
                jql.IncludeJQueryPrettyFileInput();
                //jql.IncludeFileBasedOnJQuery("blackhouse.WebNemo.Web.Scripts.edit-record.js,blackhouse.WebNemo.Web");
                //jql.IncludeFileBasedOnJQuery("blackhouse.WebNemo.Web.Scripts.radio-records.js,blackhouse.WebNemo.Web");
            }
            else
                this.Visible = false;
        }

        public virtual BaseValidator[] GetValidators() {
            return new BaseValidator[0];
        }

        public virtual string GetValue() {
            return "";
        }

        protected abstract void PopulateControl();

        public abstract void SaveInRecord();

        public virtual void ReSetValue(object value) { }

        #endregion

    }
}